package com.db.williamchart.renderer.executor;

import com.db.williamchart.data.AxisType;
import com.db.williamchart.data.Paddings;

public class MeasureBarChartPaddings {

    public Paddings invoke(
            AxisType axisType,
            float labelsHeight,
            float longestLabelWidth,
            float labelsPaddingToInnerChart
    ) {
        return measurePaddingsX(axisType, labelsHeight, labelsPaddingToInnerChart)
                .mergeWith(
                        measurePaddingsY(axisType, labelsHeight, longestLabelWidth, labelsPaddingToInnerChart)
                );
    }

    private Paddings measurePaddingsX(AxisType axisType,
                                      float labelsHeight,
                                      float labelsPaddingToInnerChart) {

        return new Paddings(
                0,
                0,
                0,
                axisType.shouldDisplayAxisX() ? labelsHeight + labelsPaddingToInnerChart : 0
        );

    }

    private Paddings measurePaddingsY(
            AxisType axisType,
            float labelsHeight,
            float longestLabelWidth,
            float labelsPaddingToInnerChart
    ) {

        if (!axisType.shouldDisplayAxisY()) {
            return new Paddings(0, 0, 0, 0);
        }

        return new Paddings(
                longestLabelWidth + labelsPaddingToInnerChart,
                labelsHeight / 2,
                0,
                labelsHeight / 2
        );
    }
}
